<?php

declare(strict_types=1);

namespace App\Repository\Article;

use App\Exception\BusinessException;
use App\Repository\BaseRepository;
use App\Model\Articles;
use Hyperf\Di\Annotation\Inject;

class ArticleRepository extends BaseRepository
{
    #[Inject]
    private Articles $articles;

    /**
     * 创建文章
     * @param array $data
     * @return object
     */
    public function create(array $data) :object
    {
        return $this->articles->create($data);
    }

    /**
     * 查询单条
     * @param int $id
     * @return object
     */
    public function getArticleDetailById(int $id): object
    {
        $article = $this->articles->find($id);
        if(!$article) {
            throw new BusinessException('文章信息不存在');
        }
       return $article;
    }
}